#include "on_off_verify.h"
#include "ui_on_off_verify.h"
#include "medical.h"
ON_Off_Verify::ON_Off_Verify(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ON_Off_Verify)
{
    ui->setupUi(this);
    QFont font("Microsoft YaHei",12,75);
    QFont font_line("宋体",12,30);

    this->setWindowTitle(tr("氧气开关设备确认界面"));
//####################
//创建一行提示信息
//###################
    //创建一个lable
    Warning_lable=new QLabel(this);
    Warning_lable->setText(QObject::tr("请输入密码以确定切换氧气设备开关"));
    Warning_lable->setGeometry(15,20,300,30);
    Warning_lable->setAlignment(Qt::AlignJustify|Qt::AlignCenter);
    Warning_lable->setFont(font);

    Passwd_lable=new QLabel(this);
    Passwd_lable->setText(QObject::tr("密码:"));
    Passwd_lable->setGeometry(10,70,50,30);
    Passwd_lable->setAlignment(Qt::AlignJustify|Qt::AlignCenter);
    Passwd_lable->setFont(font);

    passwd_line=new QLineEdit(this);
    passwd_line->setGeometry(90,70,180,30);
    passwd_line->setFont(font_line);

    OK_ptn=new QPushButton(this);
    OK_ptn->setText(QObject::tr("确定"));
    OK_ptn->setGeometry(30,130,100,30);
    cencer_ptn=new QPushButton(this);
    cencer_ptn->setText(QObject::tr("取消"));
    cencer_ptn->setGeometry(180,130,100,30);
    this->setFixedSize(320,200);//设置窗口大小为固定大小
    connect(OK_ptn,&QPushButton::clicked,this,&ON_Off_Verify::OK_ptn_clicked);
    connect(cencer_ptn,&QPushButton::clicked,this,&ON_Off_Verify::cencer_ptn_clicked);
}
bool ON_Off_Verify::CON_MYSQL_Patient()
{
    db=QSqlDatabase::addDatabase("QMYSQL","CON_Patient");
     qDebug() << "MYSQL driver valid" << db.isValid();
              db.setHostName("192.168.220.129");
              db.setPort(3306);
              db.setDatabaseName("MQTT_DATA");
              db.setUserName("root");
              db.setPassword("lama940225");
              if(!db.open())
              {
                  qDebug()<<"打开数据库失败！"<<db.lastError();
                  return false;
              }

              return true;
}
ON_Off_Verify::~ON_Off_Verify()
{


    delete ui;
}

void ON_Off_Verify::OK_ptn_clicked()
{
//    if(!CON_MYSQL_Patient())
//    {
//        QMessageBox::warning(NULL,"CONNECT DATABASE ERROR","连接数据库失败",QMessageBox::Ok);
//        return 0;
//    }
//    query=QSqlQuery(db);//对QSqlQuery::exec: database not open错误的解决方案,注意：：：一定要在连接之后才能调用，因为连接数据库之后，db1才是连接好的。
//    if(!query.exec("select * from Patient_Login_Hospital"))
//    {
//        qDebug()<<"搜索出错"<<query.lastError();
//        QMessageBox::warning(NULL,"SOURCH CLOUMNS ERROR","搜索出错",QMessageBox::Ok);
//        return 0;
//    }
//    while(query.next())
//    {
//        qDebug()<<"DDDDD";

//        if( name_text==query.value(3).toString()&&passwd_text==query.value(7).toString())
//        {
//             room_num=query.value(8).toString();
//            name_value->setText(name_text);
//            Number_value->setText(room_num);

//            qDebug()<<"TTTTTTTTTTTT"<<name_text<<passwd_text;
//            return 1;
//        }

//    }
//        return 0;


    Medical *M=new Medical();
    M->show();
    this->close();
}

void ON_Off_Verify::cencer_ptn_clicked()
{
    Medical *M=new Medical();
    M->show();
    this->close();
}
